package org.smi.youchu;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;  
import java.nio.file.Path;  
import java.nio.file.Paths;  
import java.util.Base64;  
  
public class FileToBase64 {  
  
    public static void main(String[] args) {  
        String filePath = "/Users/beyondsoft/Documents/01. 工作笔记/邮储/02. 投诉分析/测试文件/样本_06.xlsx"; // 请替换为您的文件路径
        try {  
            String base64String = encodeFileToBase64(filePath);

            FileWriter writer = new FileWriter("/Users/beyondsoft/Documents/ttt.txt");
            BufferedWriter bufferedWriter = new BufferedWriter(writer);

            bufferedWriter.write(base64String);

            bufferedWriter.close();
            System.out.println("字符串已成功写入文件");
        } catch (IOException e) {
            e.printStackTrace();  
        }  
    }  
  
    public static String encodeFileToBase64(String filePath) throws IOException {  
        Path path = Paths.get(filePath);  
        byte[] fileContent = Files.readAllBytes(path);  
        return Base64.getEncoder().encodeToString(fileContent);  
    }  
}